<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [4,7,18,20,3]  // [3,4,7,18,20]
        /* 升序算法 */
        arr.sort((a,b)=>{
            return a-b;
        })
        console.log(arr);

        /* 降序算法 */
        arr.sort((a,b)=>{
            return b-a;
        })
        console.log(arr);
    </script>
</body>
</html>